#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main() {
    int q;
    cin >> q;
    while (q--)
    {
        int arr[10] = { 0 };
        int n;
        cin >> n;
        if (n % 2 == 0)
        {
            cout << n << endl;
        }
        else
        {
            while (n)
            {
                int k = n % 10;
                n /= 10;
                arr[k]++;
            }
            string sum;
            for (int i = 0; i < 10; i += 2)
            {
                while (arr[i])
                {
                    sum += (i + '0');
                    arr[i]--;
                }
            }
            for (int i = 1; i < 10; i += 2)
            {
                while (arr[i])
                {
                    sum += (i + '0');
                    arr[i]--;
                }
            }
            reverse(sum.begin(), sum.end());
            int num = stoi(sum);
            if (num % 2)
            {
                cout << -1 << endl;
            }
            else
            {
                cout << num << endl;
            }
        }
    }
    return 0;
}


struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
 

class Solution {
public:
    priority_queue<long long> q;
    long long TreeNodeSum(TreeNode* root)
    {
        if (root == nullptr)
        {
            return 0;
        }
        long long sum = root->val;
        long long left = TreeNodeSum(root->left);
        long long right = TreeNodeSum(root->right);
        if (q.empty() || q.top() < sum)
        {
            q.push(sum);
        }
        if (q.top() < sum + left + right)
        {
            q.pop();
            q.push(sum + left + right);
        }
        if (q.top() < sum + right)
        {
            q.pop();
            q.push(sum + right);
        }
        if (q.top() < sum + left)
        {
            q.pop();
            q.push(sum + left);
        }
        return sum + max(left, right);
    }

    int maxPathSum(TreeNode* root) {
        // write code here
        TreeNodeSum(root);
        return q.top();
    }
};


const int N = 11;
int ret = 0;
int n;
bool vis[N];
int arr[N];

void dfs(int pos)
{
    if (pos == n)
    {
        ret++;
        return;
    }
    for (int i = 1; i <= n; i++)
    {
        if (vis[i])
        {
            continue;
        }
        if (vis[arr[i]])
        {
            return;
        }
        vis[i] = true;
        dfs(pos + 1);
        vis[i] = false;
    }
}


int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    dfs(0);
    cout << ret << endl;
    return 0;
}

class Solution {
public:
    int LIS(vector<int>& a) {
        // write code here
        vector<int> dp;
        int ret = 0;
        for (auto s : a)
        {
            if (ret == 0)
            {
                dp.push_back(s);
                ret++;
            }
            else if (dp[ret - 1] <= s)
            {
                dp.push_back(s);
                ret++;
            }
            else
            {
                for (int i = 0; i < ret; i++)
                {
                    if (dp[i] > s)
                    {
                        dp[i] = s;
                        break;
                    }
                }
            }
        }
        return ret;
    }
};


void cmp(int k, int i, int ret, priority_queue<int, vector<int>, greater<int>>& q)
{
    k -= i;
    if (k == 0)
    {
        q.push(ret);
        return;
    }
    if (k < 0)
    {
        return;
    }
    cmp(k, i + 1, ret + 1, q);
    cmp(k, i * 2, ret + 1, q);
}

int main() {
    int n;
    cin >> n;
    while (n--)
    {
        priority_queue<int, vector<int>, greater<int>> q;
        int k;
        cin >> k;
        cmp(k, 1, 1, q);
        cout << q.top() << endl;
    }
    return 0;
}

int main() {
    int n;
    cin >> n;
    int arr[100010] = { 0 };
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int ret = 0;
    int i = 0;
    while (i < n)
    {
        if (i == n - 1)
        {
            ret++;
            break;
        }
        if (arr[i] < arr[i + 1])
        {
            while (i + 1 < n && arr[i] <= arr[i + 1])
            {
                i++;
            }
            ret++;
        }
        else if (arr[i] > arr[i + 1])
        {
            while (i + 1 < n && arr[i] >= arr[i + 1])
            {
                i++;
            }
            ret++;
        }
        i++;
    }
    cout << ret << endl;
    return 0;
}